package sampleSuite.tests
{
	import org.flexunit.Assert;
	import org.mockito.integrations.given;
	import org.mockito.integrations.mock;
	import org.mockito.integrations.never;
	import org.mockito.integrations.times;
	import org.mockito.integrations.verify;
	
	import sample.IWarehouse;
	import sample.Order;
	
	
	[RunWith("org.mockito.integrations.flexunit4.MockitoClassRunner")]
	public class TestOrderUsingMockito 
	{
		private static const APPLE:String = "apple";
  
  		[Mock(type="sample.IWarehouse")]
  		public var warehouseMock:IWarehouse;
		
		[Before]
		public function setUp():void
		{
			warehouseMock = mock(IWarehouse);
		}
		
		[After]
		public function tearDown():void 
		{
			warehouseMock = null;
		}
		
		[Test]
		public function orderIsFilledIfEnoughInwarehouse():void 
		{
			var order:Order = new Order(APPLE,50);
			
			//given
			given(warehouseMock.getInventory(APPLE)).willReturn(50);
			
			//when
			order.fill(warehouseMock);
			
			//then
			verify(times(1)).that(warehouseMock.getInventory(APPLE));
			verify(times(1)).that(warehouseMock.remove(APPLE,50));
			Assert.assertTrue(order.isFilled());
		}
		
		[Test]
		public function orderDoesNotRemoveifNotEnough():void 
		{
			var order:Order = new Order(APPLE,51);
			
			//given
			given(warehouseMock.getInventory(APPLE)).willReturn(50);
			
			//when
			order.fill(warehouseMock);
			
			//then
			verify(times(1)).that(warehouseMock.getInventory(APPLE));
			verify(never()).that(warehouseMock.remove(APPLE,50));
			Assert.assertFalse(order.isFilled());
		}
	}
}